package com.eclipsemail.ui.editor;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;

import com.eclipsemail.core.message.EmailMessage;
import com.google.common.base.Preconditions;

public class MailEditorInput implements IEditorInput {

    private EmailMessage mail;

    public MailEditorInput(EmailMessage mail) {
        this.mail = Preconditions.checkNotNull(mail);
    }

    @Override
    public boolean exists() {
        return false;
    }

    // Legacy code, supertype dont uses generics
    @SuppressWarnings("rawtypes")
    @Override
    public Object getAdapter(Class adapter) {
        return Platform.getAdapterManager().getAdapter(this, adapter);
    }

    @Override
    public ImageDescriptor getImageDescriptor() {
        return null;
    }

    @Override
    public String getName() {
        return this.mail.getTitle();
    }

    @Override
    public IPersistableElement getPersistable() {
        return null;
    }

    @Override
    public String getToolTipText() {
        return "";
    }

    public EmailMessage getMail() {
        return mail;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj instanceof MailEditorInput) {
            return mail.equals(((MailEditorInput) obj).getMail());
        }
        return false;
    }

    @Override
    public int hashCode() {
        return mail.hashCode();
    }

}
